package com.sgb.member.ui.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.sgb.member.R
import com.sgb.member.databinding.SelectMemberPriceItemBinding
import com.sgb.member.entity.MemberBean2

class SelectMembarPriceAdapter(var data: MutableList<MemberBean2>?) : RecyclerView.Adapter<SelectMembarPriceAdapter.ViewHolder>() {


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val binding: SelectMemberPriceItemBinding = DataBindingUtil.inflate(LayoutInflater.from(parent.context),
                R.layout.select_member_price_item, parent, false);
        return ViewHolder(binding)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
         data?.get(position)?.run {
             holder.binding.bean = this
            if (isSelect) {
                holder.binding.ivSelect.setImageResource(R.mipmap.btn_checed)
            } else {
                holder.binding.ivSelect.setImageResource(R.mipmap.btn_uncheced)
            }
            holder.binding.ivSelect.setOnClickListener {
                isSelect = !isSelect
                notifyDataSetChanged()
            }
        }
        holder.binding.executePendingBindings()
    }

    override fun getItemCount(): Int = data?.size ?:0


    inner class ViewHolder(val binding: SelectMemberPriceItemBinding) : RecyclerView.ViewHolder(binding.root)
}

